Title: Exporter
Order: 5
TexSample: true
---

<p>
	AlphaTab can export an already loaded track as alphaTex. 
</p>

<div id="alphaTabExporter">
	Open a Guitar Pro file by clicking here to export the 
	first track as alphaTex.
	<input type="file" id="exporterFile" />
</div>

<div class="texSample">
	<pre><code class="language-JavaScript line-numbers">function toTex(track) {
var exporter = new AlphaTab.Exporter.AlphaTexExporter();
exporter.Export(track);
return exporter.ToTex(); 
}</code></pre>
</div>

<h2>Exported AlphaTex</h2>

<div id="alphaTabExportedAlphaTex">
<code class="language-alphaTex line-numbers">
Open a file to see the generated alphaTex here. 
</code>
</pre>

<script type="text/x-alphatab" id="alphaTabExporterCode">
function exportFile(data) {
	// parse score
	var score = null;
	try {
		score = AlphaTab.Importer.ScoreLoader.LoadScoreFromBytes(data);
	}
	catch(e) {
		alert('Failed to load file, did you really open a Guitar Pro file?');
	}
	
	// export it 
	if(score != null) {
		var exporter = new AlphaTab.Exporter.AlphaTexExporter();
		exporter.Export(score.Tracks[0]);
		var tex = exporter.ToTex(); 
						
		var code = $('<code class="language-alphaTex line-numbers"></code>')
			.text(tex);   

		var pre = $('<pre></pre>').append(code);    
		
		$('#alphaTabExportedAlphaTex')
			.empty()
			.append($('<div class="texSample"></div>').append(pre));
		Prism.highlightElement(code[0]);
	}
}

$('#exporterFile').change(function(e) {
	debugger;
	var files = e.originalEvent.target.files;
	if(files.length > 0) {
		var reader = new FileReader();
		reader.onload = (function(e) {
			exportFile(new Uint8Array(e.target.result));
		});
		reader.readAsArrayBuffer(files[0]);
	}
});
</script>

</div>
